package com.raven.craft.code.generator.mysql.mybatis;

import com.google.common.collect.Sets;
import com.raven.craft.code.generator.common.util.StringUtil;
import com.raven.craft.code.generator.mysql.repo.entity.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Set;

/**
 * @author raven
 * @date 2019-04-04 17:42
 */
@Getter
@Setter
@ToString
public class MapperVo {

    public String targetPackage;
    public String name;

    private String entityName;
    private String entityTypePath;
    private Set<String> imports;

    public MapperVo(MyBatisProperties properties, Table table) {
        this.targetPackage = properties.getMapperPackage();
        this.entityName = StringUtil.trim(table.getName(), properties.getTrimPrefix(), properties.getTrimSuffix());
        this.entityTypePath = properties.getEntityPackage() + "." + entityName;
        this.name = this.entityName + "Mapper";
        this.imports = generateImportTypeSet(table);
    }

    private Set<String> generateImportTypeSet(Table table) {
        Set<String> set = Sets.newHashSet();

        set.add(entityTypePath);
        set.add("com.baomidou.mybatisplus.core.mapper.BaseMapper");
        set.add("org.apache.ibatis.annotations.Mapper");

        return set;
    }

}
